/**********************************************************************
  * @file:        xxx.c
  * @author:      guangjieMVP
  * @version:     v1.00.00
  * @date:        2020-xx-xx
  * @github:      https://github.com/guangjieMVP
  * @brief: 
************************************************************************/
#include "stack_with_range_check.h"

/**********************************************************************
  * @brief:         初始化对象(构造函数)
  * @param[in]:     None
  * @retval[out]:   None
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_range_check_init(stack_rang_check_t *s, int *s_buffer, int size, int max, int min)
{
    if(!s || !s_buffer || size <= 0)
        return -1;

    stack_init(&s->super, s_buffer, size);
    s->max = max;
    s->min = min;
    return 0;
}

/**********************************************************************
  * @brief:         解初始化对象(析构函数)
  * @param[in]:     None
  * @retval[out]:   None
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_range_check_deinit(stack_rang_check_t *s)
{
    s->max = 0;
    s->min = 0;
    return stack_deinit(&s->super);    
}

/**********************************************************************
  * @brief:         入栈
  * @param[in]:     None
  * @retval[out]:   None
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_range_check_push(stack_rang_check_t *s, int val)
{
    if(!s)
        return -1;

    if(val >= s->min && val < s->max)
    {
        return stack_push(&s->super, val);     //复用父类的入栈函数
    }
    return -1;
}

/**********************************************************************
  * @brief:         出栈
  * @param[in]:     None
  * @retval[out]:   None
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_range_check_pop(stack_rang_check_t *s, int *val)
{
    if(!s || !val)
        return -1;
     
    return stack_pop(&s->super, val);      //复用父类的出栈函数
}